import requests

url = 'https://www.wanandroid.com/user/login'
payload = {
    'username': 'weixuesong',
    'password': 'wxs2011133069'
}
response = requests.post(url, data=payload)

print('----Request Headers----')
print(response.request.headers)

print('----Response Headers----')
print(response.headers)

cookies = response.cookies
print('----Response Cookie----')
print(cookies)

print('----Response Body----')
print(response.json())


cookie_dict: dict = cookies.get_dict()
print('----Response Cookie Dict----')
print(cookie_dict)

url = 'https://www.wanandroid.com/user/lg/userinfo/json'
headers = {
    'Cookie': '; '.join(f'{k}={v}' for k, v in cookie_dict.items())
}
print('----Request Headers----')
print(headers)

# 携带cookie发送请求方式一：
response = requests.get(url, headers=headers)
print(response.json())

# 携带cookie发送请求方式二：
response = requests.get(url, cookies=cookies)
print(response.json())
